package com.dao;

import com.domain.sys.SysMenu;
import com.domain.Node;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.HashMap;

@Mapper
public interface SysMenuDao {
    ArrayList<HashMap<String,Object>> findObject();

    @Select("select count(*) from sys_menus where parentId = #{id}")
    Integer getChildCount(Integer id);


    @Delete("delete from sys_menus where id = #{id}")
    Integer deleteObject(Integer id);

    @Select("select id,name,parentId from sys_menus")
    ArrayList<Node> findZtreeMenuNodes();

    @Insert(" insert into sys_menus" +
            "(name,url,type,sort,note,parentId,permission," +
            "createdTime,modifiedTime,createdUser,modifiedUser)" +
            "values" +
            "(#{name},#{url},#{type},#{sort},#{note},#{parentId}," +
            "#{permission},now(),now(),#{createdUser},#{modifiedUser})")
    Integer insertObject(SysMenu entity);

    @Update(" update sys_menus" +
            " set" +
            " name=#{name}," +
            " type=#{type}," +
            " sort=#{sort}," +
            " url=#{url}," +
            " parentId=#{parentId}," +
            " permission=#{permission}," +
            " modifiedUser=#{modifiedUser}," +
            " modifiedTime=now()" +
            " where id=#{id}")
    Integer updateObject(SysMenu sysMenu);
}
